<template>
  <div class="specs_wrap">
    <BreadCrumb crumb="优惠券管理"></BreadCrumb>
    <div class="top_bar">
      <AddCoupon @fnResetTable="fnGetData(1);"></AddCoupon>
    </div>
    <CouponTable
      :coupons="couponsList"
      @fnResetTable="fnGetData(1);"
    ></CouponTable>
    <el-pagination
      background
      layout="prev, pager, next"
      :total="total"
  
      :page-size="pagesize"
      :current-page="page"
      style="text-align:center;margin-top:10px"
      @current-change="fnGetPage"
    >
    </el-pagination>
  </div>
</template>

<script>
import BreadCrumb from "@/components/widget/BreadCrumb";
import AddCoupon from "@/components/widget/AddCoupon";
import CouponTable from "@/components/widget/CouponTable";
import cons from "@/components/constant";

export default {
  name: "Coupon",
  components: {
    BreadCrumb,
    AddCoupon,
    CouponTable
  },
  data() {
    return {
      page:1,
      total:0,
      pagesize:2,
      couponsList: []
    };
  },
  mounted() {
    // 获取所有的规格信息
    this.fnGetData(1);
  },
  methods: {
    fnGetData: function(num) {
      let token = localStorage.token;
      this.axios
        .get(cons.apis + "/coupons/coupons/", {
          headers: {
            Authorization: "JWT " + token
          },
          responseType: "json",
          params: {
            page: num,
            pagesize: this.pagesize
          }
        })
        .then(dat => {
          console.log("优惠券数据>>", dat.data);
          this.couponsList = dat.data.results;
          this.total = dat.data.count;
          this.page = dat.data.page;
          this.pages = dat.data.pages;
        })
        .catch(err => {
          console.log(err);
        });
    },
    fnGetPage: function(dat) {
      this.page = dat;
      this.fnGetData(this.page);
    }
  }
};
</script>
<style scoped>
.top_bar {
  width: 95.2%;
  overflow: hidden;
  margin: 10px auto;
}
</style>
